home *** CD-ROM | disk | FTP | other *** search
- /* PROGRAM CPROG1.CPP
-
- Press Ctrl+F9 to compile and run this program.
-
- Press F5 to zoom the window. See the Window menu (Alt+W) for more
- window-related commands. Also have a look at the Help system (Alt+H).
- Note that F1 gives context-sensitive help. Now press the down cursor
- key to put the dashed line at the top of the window
- ----------------------------------------------------------------------
- The next two lines are preprocessor commands. The first #include causes
- the file STDIO.H to be read at that point. Then CONIO.H is read. It's
- as though the contents of those two files replaced the #include lines
- in which they are named.
- Files that end in .H are called header files. They contain important
- information that the compiler needs to know about ready-compiled library
- functions. Header files can also store often-repeated information like
- the definition of macros that you use time and again. Macros will
- be covered in more detail another time. See #define under Help/Index
- if you want to push ahead on this.
- STDIO.H includes information about printf(), a function supplied
- in the libraries accompanying TC Lite and used in this program.
- Kbhit() is covered in CONIO.H. The on-line help will tell you which
- header file you need to #include for a particular function.
- Note how this comment spans several lines, yet only its start and
- end points need to be indicated. */
-
- #include <stdio.h>
- #include <conio.h>
-
- main()
- {
- /*------------------------------------------------------------------+
- | The next lines use the printf() function to print a message |
- | NOTE: |
- | - The ; character on the end of every C/C++ command. |
- | - The \n in the middle of the print string. The \ character |
- | allows you to embed special codes within strings. |
- | \n means 'new line'. \t is a tab. There are others. |
- | - That these comments are all ignored by the compiler because of |
- | the enclosing slash-star and star-slash. The bordering -, + and |
- | | characters are purely optional embelishments. |
- | - Comments cannot be placed within comments, which is why I had |
- | to write slash-star and star-slash rather than the actual |
- | characters - the compiler would get confused! |
- +-------------------------------------------------------------------*/
-
- printf("Come on in\nThe C's lovely!");
- printf("\n\nPress a key...\n");
-
- /*-----------------------------------------------------------------------+
- | Note how the string to be printed is passed to the program code inside |
- | printf() by putting it between the brackets. This mechanism for passing|
- | parameters to functions will be covered later in the series. |
- +-----------------------------------------------------------------------*/
-
- // The next bit pauses program execution until you press a key.
-
- while ( kbhit() == 0 )
- ;
-
- /*------------------------------------------------------------------+
- | NOTE: |
- | - How the single-line comment above just needed a preceding // |
- | - WHILE executes the command after it while the condition |
- | inside the brackets is true. Since the while(...) construct |
- | is immediately followed by a ; character and ; marks the end of |
- | a command, this loop doesn't have anything to do other than |
- | continually test the condition. |
- | - kbhit() is a function supplied in a library with the compiler. |
- | It tests whether or not a key has been pressed. If it hasn't, |
- | it comes back with (returns) the number '0' meaning false. Put |
- | the cursor anywhere in kbhit() and press Ctrl+Shift+F1 to read |
- | more about it. Esc returns you here. |
- | - == is a C operator meaning 'is equal to' and is used in equality|
- | tests only. A single = is used when you assign a value to a |
- | variable. |
- | - The line above therefore translates as: |
- | 'If the number reported by the function kbhit() is equal to 0, |
- | do nothing and repeat the test' |
- +------------------------------------------------------------------*/
- }
- /*--------------------------------------------------------------------+
- | Program execution never gets this far... it automatically ends when |
- | it meets the brace at the end of Main. Press Ctrl+F9 to compile and |
- | run this program. |
- +--------------------------------------------------------------------*/
-